<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>imagegetpixel</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="imagefree.html" title="imagefree" />
    <link rel="next" href="imageload.html" title="imageload" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">imagegetpixel</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="imagefree.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="imageload.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="imagegetpixel"></a>
      <div class="titlepage"></div>
      <a id="IndexImagegetpixel" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">imagegetpixel</span>
        </h2>
        <p>imagegetpixel — 
      Return the RGB pixel values of a previously opened or created image.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115529936"></a>
        <h2>Description</h2>
        <p>Return the RGB pixel values of a previously opened or created image. An image can be loaded with <a class="link" href="imageload.html" title="imageload"><em class="citetitle">imageload</em></a>. An empty image can be created with <a class="link" href="imagecreate.html" title="imagecreate"><em class="citetitle">imagecreate</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115597376"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ared, agreen, ablue <span class="command"><strong>imagegetpixel</strong></span> iimagenum, ax, ay</pre>
        <pre class="synopsis">kred, kgreen, kblue <span class="command"><strong>imagegetpixel</strong></span> iimagenum, kx, ky</pre>
      </div>
      <div class="refsect1">
        <a id="idp115600960"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iimagenum</em></span> -- the reference of the image.. It should be a value returned by <a class="link" href="imageload.html" title="imageload"><em class="citetitle">imageload</em></a> or <a class="link" href="imagecreate.html" title="imagecreate"><em class="citetitle">imagecreate</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115604512"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ax (kx)</em></span> -- horizontal pixel position (must be a float from 0 to 1).
    </p>
        <p>
      <span class="emphasis"><em>ay (ky)</em></span> -- vertical pixel position (must be a float from 0 to 1).
    </p>
        <p>
      <span class="emphasis"><em>ared (kred)</em></span> -- red value of the pixel (mapped to a float from 0 to 1).
    </p>
        <p>
      <span class="emphasis"><em>agreen (kgreen)</em></span> -- green value of the pixel (mapped to a float from 0 to 1).
    </p>
        <p>
      <span class="emphasis"><em>ablue (kblue)</em></span> -- blue value of the pixel (mapped to a float from 0 to 1).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115610064"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the imagegetpixel opcode. It uses the files <a class="ulink" href="examples/imageopcodesdemo2.csd" target="_top"><em class="citetitle">imageopcodesdemo2.csd</em></a> <a class="ulink" href="examples/test1.png" target="_top"><em class="citetitle">test1.png</em></a> and <a class="ulink" href="examples/test2.png" target="_top"><em class="citetitle">test2.png</em></a>.
      </p>
        <div class="example">
          <a id="idp115613520"></a>
          <p class="title">
            <strong>Example 387. Example of the imagegetpixel opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac           -iadc    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o imageopcodesdemo2.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
 
<span class="ohdr">sr</span>      <span class="op">=</span>      	48000 
<span class="ohdr">ksmps</span>  	<span class="op">=</span>     	100
<span class="ohdr">nchnls</span>	<span class="op">=</span>	2

<span class="comment">;By Cesare Marilungo 2008</span>
<span class="opc">zakinit</span> 10,1

<span class="comment">;Load the image - should be 512x512 pixels</span>
giimage <span class="opc">imageload</span> "test1.png"
<span class="comment">;giimage imageload "test2.png" ;--try this too</span>
giimagew, giimageh <span class="opc">imagesize</span> giimage

giwave <span class="ohdr">ftgen</span> 1, 0, 1024, 10, 1
gifrqs <span class="ohdr">ftgen</span> 2,0,512,<span class="op">-</span>5, 1,512,10
giamps <span class="ohdr">ftgen</span> 3, 0, 512, 10, 1

	<span class="oblock">instr</span> 100

kindex <span class="op">=</span> 0
icnt <span class="op">=</span> giimageh
kx_ <span class="opc">linseg</span> 0, p3, 1
kenv <span class="opc">linseg</span> 0, .2, 500, p3 <span class="op">-</span> .4, 500, .2, 0

<span class="comment">; Read a column of pixels and store the red values</span>
<span class="comment">; inside the table 'giamps'</span>
<span class="olabel">loop</span><span class="op">:</span>
    ky_ <span class="op">=</span> kindex<span class="op">/</span>giimageh

    <span class="comment">;Get the pixel color values at kx_, ky_</span>
    kred, kgreen, kblue <span class="opc">imagegetpixel</span> giimage, kx_, ky_

    <span class="comment">;Write the red values inside the table 'giamps'</span>
    <span class="opc">tablew</span> kred, kindex, giamps
    kindex <span class="op">=</span> kindex<span class="op">+</span>1

<span class="octrl">if</span> (kindex <span class="op">&lt;</span> icnt) <span class="octrl">kgoto</span> <span class="olabel">loop</span>

<span class="comment">; Use an oscillator bank (additive synthesis) to generate sound</span>
<span class="comment">; setting amplitudes for each partial according to the image</span>
asig <span class="opc">adsynt</span> kenv, 220, giwave, gifrqs, giamps, icnt, 2
<span class="opc">outs</span> asig, asig

	<span class="oblock">endin</span>

	<span class="oblock">instr</span> 101
<span class="comment">; Free memory used by the image</span>
<span class="opc">imagefree</span> giimage
	<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">t</span> 0 60

<span class="stamnt">i</span>100 1 20 
<span class="stamnt">i</span>101 21 1

<span class="stamnt">e</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115615440"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="imageload.html" title="imageload"><em class="citetitle">imageload</em></a>,
      <a class="link" href="imagecreate.html" title="imagecreate"><em class="citetitle">imagecreate</em></a>,
      <a class="link" href="imagesize.html" title="imagesize"><em class="citetitle">imagesize</em></a>,
      <a class="link" href="imagesave.html" title="imagesave"><em class="citetitle">imagesave</em></a>,
      <a class="link" href="imagesetpixel.html" title="imagesetpixel"><em class="citetitle">imagesetpixel</em></a>,
      <a class="link" href="imagefree.html" title="imagefree"><em class="citetitle">imagefree</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp115622320"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Cesare Marilungo</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 5.08</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="imagefree.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="imageload.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">imagefree </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> imageload</td>
        </tr>
      </table>
    </div>
  </body>
</html>
